<?php
session_start();

// Parametros de configuracion
include_once('../../config/configuracion.php');

// Funciones de acceso a BD
include_once('../../dao/interface_db.php');

//if (isset($_SESSION['paramdb']) && isset($_SESSION['USUARIO'])){
if (isset($_SESSION['paramdb'])){
		
	$objdb = new DBSql($_SESSION['paramdb']);
	$objdb -> db_connect();
		
	if ($objdb -> is_connection()){
?>
	<div class="portlet-header fixed">
        	<img src="../../theme/images/icons/page_find.gif" width="16" height="16" alt="" /> Filtrar por:
    </div>
	<form id="filtro" action="" method="post">
		<table width="100%" cellpadding="0" cellspacing="0" id="box-table-a">
            <tbody>
				<tr>
					<td>&nbsp;</td>
					<td>Pais:</td>
					<td width="400">
						<select id="cboPais" class="smallInput" onChange="Limpiar_Pagina();">
							<option value="0">--Todos--</option>
	<?php
							$rsPaises = $objdb -> sqlListaPaises();
							if (mysql_num_rows($rsPaises)!=0){
								while ($row = mysql_fetch_array($rsPaises)){
									$idPaisP = $row["idPais"];
									$pais = $row["Descripcion"];
									
									if($idPais==$idPaisP){
	?>
										<option value="<?= $idPaisP; ?>" Selected><?= $pais; ?></option>
	<?php
									}else{
	?>			
										<option value="<?= $idPaisP; ?>"><?= $pais; ?></option>
	<?php									
									}
								}
								mysql_free_result($rsPaises);
							}
	?>	
						</select>
					</td>
					<td>&nbsp;</td>
					<td>
						<a href="#" class="button_grey_round" onClick="Filtrar_Departamentos()"><span>Filtrar</span></a>
					</td>
					<td>
						<a href="#" class="button_grey_round" onClick="Operacion_Departamento('0','agregar')"><span>Agregar</span></a>
					</td>					
					<td>&nbsp;</td>
				</tr>
				<tr><td colspan="7"></td>
				</tr>
            </tbody>
          </table>
	</form>

<?php
	}
}else{
	header("Location: error.php");
  	exit();
}

?>	

<script type="text/javascript">
	function Filtrar_Departamentos(){
		
		var idPais = $("#cboPais").val();
		
		$("#content_portlet").html("<center><img src='images/ajax-loader.gif'><br><b>Actualizando el contenido.</b>"+
													"<br>Por favor espere...</center>");
		$("#content_portlet").load("listaDepartamentos.php?p="+Math.random(), {idPais: idPais});		
		
	}
	

</script>